package com.systar.activity.parse;

import com.google.common.eventbus.EventBus;
import com.systar.activity.state.FileActivity;

public class ParserFactory
{
	private ParserFactory()
	{
		// none 
	}

	public static FileParser getParser(FileActivity activity, EventBus eventBus)
	{
		String fileExtension = getFileExtension(activity.getFile().getName());
		if ("txt".compareToIgnoreCase(fileExtension) == 0)
		{
			return new TxtLogFileParser(activity, eventBus);
		}
		if ("xsession".compareToIgnoreCase(fileExtension) == 0)
		{
			return new SessionFileParserRegExp(activity, eventBus);
			//return new SessionFileParserSax(activity, eventBus);
			//return new SessionFileParserLexer(activity, eventBus);
		}
		return null;
	}

	private static String getFileExtension(String path)
	{
		int pos = path.lastIndexOf(".");
		if (pos == -1)
		{
			return null;
		}
		return path.substring(pos + 1);
	}
}
